package Leetcode.图;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: kirito
 * @Date: 2024/9/8 16:22
 * @Description: 图工具类
 *
 */

public class GraphUtils {
    public static List<Integer>[] getGraph(int n, int[][] edges) {
        List<Integer>[] graph = new ArrayList[n];
        Arrays.setAll(graph, e -> new ArrayList<>());
        for (int[] e : edges) {
            int x = e[0], y = e[1];
            graph[x].add(y);
            graph[y].add(x); // 建图
        }
        return graph;
    }
}
